Download this file

142 lines (115 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef GENTABLES_H_INCLUDED
#define GENTABLES_H_INCLUDED
#include <cstdint>
#include <map>
#include <vector>
/// Application class for generating the dual marching cubes and manifold
/// dual marching cubes tables.
class GenerateTablesApp {
public:
/// Run the application.
void run();
private:
// forward declarations
class CoordinateAxis;
class CubeConfiguration;
class CubeCornerCode;
// copy from dualmc.h
enum DMCEdgeCode {
EDGE0 = 1,
EDGE1 = 1 << 1,
EDGE2 = 1 << 2,
EDGE3 = 1 << 3,
EDGE4 = 1 << 4,
EDGE5 = 1 << 5,
EDGE6 = 1 << 6,
EDGE7 = 1 << 7,
EDGE8 = 1 << 8,
EDGE9 = 1 << 9,
EDGE10 = 1 << 10,
EDGE11 = 1 << 11,
FORCE_32BIT = 0xffffffff
};
using ProblematicConfigsMap = std::map<uint8_t,uint32_t>;
private:
// functions for generating the manifold dual marching cubes table
template<class T> void registerConfigAxisRotations(T f, CubeConfiguration cubeConfiguration, CoordinateAxis const axis, ProblematicConfigsMap & problematicConfigsMap);
void exploreConfigRotations(CubeConfiguration config, ProblematicConfigsMap & problematicConfigsMap);
void generateManifoldTable(ProblematicConfigsMap & problematicConfigsMap);
void writeManifoldTable(ProblematicConfigsMap const & problematicConfigsMap);
// functions for generating the dual marching cubes table
void generateDualMCTable(std::vector<uint32_t> & dualPointsList);
void writeDualMCTable(std::vector<uint32_t> const & dualPointsList);
/// Table for retrieving the edges adjacent to a cube corner.
static uint32_t const cornerEdges[8][3];
};
/// Class for a cube configuration represented by the corners in/out classification.
class GenerateTablesApp::CubeConfiguration {
public:
// in bit-mask for for each corner
static constexpr uint8_t C0 = 1;
static constexpr uint8_t C1 = 2;
static constexpr uint8_t C2 = 4;
static constexpr uint8_t C3 = 8;
static constexpr uint8_t C4 = 16;
static constexpr uint8_t C5 = 32;
static constexpr uint8_t C6 = 64;
static constexpr uint8_t C7 = 128;
/// Initializing constructor.
CubeConfiguration(uint8_t c) : config(c) {}
/// Get the configuration value
uint8_t get() const { return config; }
/// Rotate cube configuration around x axis.
void rotX();
/// Rotate cube configuration around y axis.
void rotY();
/// Rotate cube configuration around z axis.
void rotZ();
private:
uint8_t config;
};
/// Class for representing a coordinate axis.
class GenerateTablesApp::CoordinateAxis {
public:
/// Axis value enum
enum class Value : uint32_t {
NX = 0,
PX = 1,
NY = 2,
PY = 3,
NZ = 4,
PZ = 5
};
/// Initializing constructor
CoordinateAxis(Value v);
/// Rotate axis around x axis.
void rotX();
/// Rotate axis around y axis.
void rotY();
/// Rotate axis around z axis.
void rotZ();
/// Get the stored axis value.
Value get() const;
private:
Value value;
};
/// Cuber corner stored as a Morton node.
class GenerateTablesApp::CubeCornerCode {
public:
/// Initializing constructor.
CubeCornerCode(uint8_t c) : code(c) {}
/// Get the bit mask where the bit corresponding to the code value is set.
uint32_t getMask() const { return 1u << code;}
/// Get the Morton code.
uint32_t getCode() const { return code;}
/// Get the code of the neighbor in x direction.
uint32_t nX() const { return code ^ 1;}
/// Get the code of the neighbor in y direction.
uint32_t nY() const { return code ^ 2;}
/// Get the code of the neighbor in z direction.
uint32_t nZ() const { return code ^ 4;}
private:
/// Morton code of the corner
uint32_t code;
};
#endif // GENTABLES_H_INCLUDED